import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Date;


public class MysqlDB {
	private Connection connect = null;
	private PreparedStatement preparedStatement = null;
	private ResultSet resultSet = null;
	
	public MysqlDB(String host, String userName, String password, String dbName){
		try {
			Class.forName("com.mysql.jdbc.Driver");
			
			// setup the connection with the DB.
		    this.connect = DriverManager.getConnection(String.format("jdbc:mysql://%s/%s?user=%s&password=%s", host, dbName, userName, password));
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public ResultSet executeQuery(String query)
	{
		ResultSet result = null;
		
		try {
			Statement statement = this.connect.createStatement();
			result = statement.executeQuery(query);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
		return result;
	}
	
	public int executeNoneQuery(String query)
	{
		int result = -1;
		
		try {
			Statement statement = this.connect.createStatement();
			result = statement.executeUpdate(query);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return result;
	}
	
	public Boolean close(){
		try {
			this.connect.close();
			return true;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return false;
		}
	}
}
